const ModuleUser = {
    initState: {

    },
    state: {
        id: "",
        age: "",
        email: "",
        username: "未登录",
        gender: "",
        picture: "",
        followers: 0,
        subscribes: 0,
        is_login: false,
        jwtToken: "",
        articleCount: 0,
    },
    getters: {

    },
    // actions 处理异步  mutations 处理赋值这样的操作 
    mutations: {
        ResetState(state) {
            state.username = '';
            state.is_login = false;
            state.id = '';
            state.age = 0;
            state.email = '';
            state.gender = false;
            state.followers = 0;
            state.subscribes = 0;
            state.jwtToken = '';
            state.picture = '';
            state.articleCount = 0;
        },
        UserRebuild(state, resp) {
            let user = JSON.parse(resp);

            state.username = user.username;
            state.is_login = true;
            state.id = user.id;
            state.age = user.age;
            state.email = user.email;
            state.gender = user.gender;
            state.followers = user.followers;
            state.subscribes = user.subscribes;
            state.jwtToken = user.jwtToken;
            state.picture = user.picture;
            state.articleCount = user.articleCount;
            console.log("rebuild");
        },
        UserHasLogin(state, resp) {
            state.is_login = true;
            state.id = resp.id;
            state.age = resp.age;
            state.email = resp.email;
            state.username = resp.name;
            state.gender = resp.gender;
            state.followers = resp.followers;
            state.subscribes = resp.subscribes;
            state.jwtToken = resp.jwtToken;
            state.picture = resp.picture;
            state.articleCount = resp.articleCount;

            localStorage.setItem('token', state.jwtToken)
        }
    },
    actions: {

    },
    modules: {

    }
};

export default ModuleUser;
